import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import Login from '../views/login.vue'
import Register from '../views/register.vue'
import AuditUser from '../views/AuditUser.vue'
import AuditParkingSpace from '../views/AuditParkingSpace.vue'
import UpdateParkingSpaceGetPart from '../views/UpdateParkingSpaceGetPart.vue'
import AuditRecordQuery from '../views/AuditRecordQuery.vue'
import Test from '../views/test.vue'
import RentMessageQuery from '../views/RentMessageQuery.vue'
import PropertyManager from '../views/PropertyManager.vue'

Vue.use(VueRouter)

const routes = [{
        path: '/',
        name: 'Login',
        component: Login,
        meta: {
            showNav: true
        }
    },
    {
        path: '/login',
        name: 'Login',
        component: Login,
        meta: {
            showNav: true
        }
    },
    {
        path: '/auditUser',
        name: 'AuditUser',
        component: AuditUser
    },
    {
        path: '/propertyManager',
        name: 'PropertyManager',
        component: PropertyManager
    },
    {
        path: '/rentMessageQuery',
        name: 'RentMessageQuery',
        component: RentMessageQuery
    },
    {
        path: '/test',
        name: 'Test',
        component: Test
    },
    {
        path: '/auditParkingSpace',
        name: 'AuditParkingSpace',
        component: AuditParkingSpace
    },
    {
        path: '/updateParkingSpaceGetPart',
        name: 'UpdateParkingSpaceGetPart',
        component: UpdateParkingSpaceGetPart
    },
    {
        path: '/auditRecordQuery',
        name: 'AuditRecordQuery',
        component: AuditRecordQuery
    },

    {
        path: '/register',
        name: 'Register',
        component: Register,
        meta: {
            showNav: true
        }
    },


]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})

router.beforeEach((to, from, next) => {

    if (to.path == "/" || to.path == "/login" || to.path == "/register") {

        next();
    } else {

        if (localStorage.getItem("manager")) {

            next();
        } else {

            router.push({
                path: "/login",
                query: { message: "请先登录" }
            })
        }
    }
})

export default router